package com.konsung.ksdc.manager.addr;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.konsung.ksdc.R;
import com.konsung.ksdc.bean.AddrAdvanceBean;
import com.konsung.ksdc.bean.AddrUltimateBean;
import com.konsung.ksdc.common.utils.ActivityCollector;
import com.konsung.ksdc.manager.appmain.BaseActivity;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/5/16 0016.
 */
public class DistrictStep2 extends BaseActivity {
    @Bind(R.id.rl_back)
    RelativeLayout rlBack;
    @Bind(R.id.tab_tv_title)
    TextView tabTvTitle;
    @Bind(R.id.tv_save)
    TextView tvSave;
    @Bind(R.id.rl_title_container)
    RelativeLayout rlTitleContainer;
    @Bind(R.id.lv_area)
    ListView lvArea;
    public static final String CITY_NAME = "county_name";
    public static final String CITY_CODE = "county_code";
    public static final String COUNTY_DATA = "county_data";
    private String provinceName;
    private String provinceCode;
    private AddrUltimateBean datas;

    @Override
    protected String activityDesc() {
        return getString(R.string.page_choose_district2);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_district_step);
        ButterKnife.bind(this);
        ActivityCollector.addActivity(DistrictStep2.this);
        initData();
        initView();
    }

    /**
     * init view
     */
    private void initView() {
        tabTvTitle.setText(R.string.title_addr_step1);
        rlBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityCollector.removeActivity(DistrictStep2.this);
                finish();
            }
        });
        lvArea.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int
                    position, long id) {

                AddrAdvanceBean bean = datas.getAearList().get(position);
                Intent intent = new Intent(DistrictStep2.this, DistrictStep3
                        .class);
                intent.putExtra(DistrictStep2.COUNTY_DATA, bean);
                intent.putExtra(DistrictStep2.CITY_NAME, provinceName + "&" +
                        bean.getAreaName());
                intent.putExtra(DistrictStep2.CITY_CODE, provinceCode + "&" +
                        bean.getAreaId());
//                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent
//                        .FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
            }
        });

    }

    /**
     * init data
     */
    private void initData() {
        datas = getIntent().getParcelableExtra(DistrictStep1.CITY_DATAS);
        provinceName = getIntent().getStringExtra(DistrictStep1
                .PROVINCE_NAME);
        provinceCode = getIntent().getStringExtra(DistrictStep1
                .PROVINCE_CODE);
        lvArea.setAdapter(new DistrictCityAdapter(this, datas.getAearList(),
                provinceName));
    }
}
